package pl.edu.agh.agents.gui.actions;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import pl.edu.agh.agents.gui.GUI;

public class ShowGenerateDialogAction extends AbstractAction {
	private static final long serialVersionUID = 1416422056403961231L;
	private GUI gui;

	public ShowGenerateDialogAction(String name, GUI gui) {
		super(name);

		this.gui = gui;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		//Create and set up the window.
		JDialog dialog = new JDialog(gui, "Generate graph");
		dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

		JTextField filename = new JTextField(15);
		JTextField states = new JTextField(15);
		JTextField agents = new JTextField(15);
		JSlider densitySlider = new JSlider(1, 100, 10);

		//Set up the content pane.
		Container contentPane = dialog.getContentPane();
		GridLayout layout = new GridLayout(5, 3);

		contentPane.setLayout(layout);
		contentPane.add(new JLabel("Filename: ", SwingConstants.RIGHT));
		contentPane.add(filename);
		contentPane.add(new JButton(new ShowBrowseDialogAction("Browse...", filename, gui)));

		contentPane.add(new JLabel("Number of states: ", SwingConstants.RIGHT));
		contentPane.add(states);
		contentPane.add(new JLabel(""));

		contentPane.add(new JLabel("Number of agents: ", SwingConstants.RIGHT));
		contentPane.add(agents);
		contentPane.add(new JLabel(""));

		contentPane.add(new JLabel("Sparse", SwingConstants.RIGHT));
		contentPane.add(densitySlider);
		contentPane.add(new JLabel("Dense"));

		JButton generate = new JButton(new GenerateAction("Generate", filename, states, agents, densitySlider, dialog));
		generate.setText("Generate");
		contentPane.add(new JLabel(""));

		contentPane.add(generate);

		//Display the window.
		dialog.pack();
		dialog.setVisible(true);		
	}
}